<template>
  <view class="setting_container">
    <view class="gradient-bg">
      <!-- <image :src="myBgSrc" class="wdbg" mode="cover"></image> -->
      <view class style="width: 92%;margin: 0rpx auto;">
        <view class="big-line">
          <view @click="toPrivate('private')" class="row-line">
            用户协议
            <text style class="iconfont icon-xiangyou arrow"></text>
          </view>
          <view @click="toPrivate('policy')" class="row-line">
            隐私政策
            <text style class="iconfont icon-xiangyou arrow"></text>
          </view>
          <!-- <view @click="wen" class="row-line">
            修改密码
            <text style class="iconfont icon-xiangyou arrow"></text>
          </view>
          <view @click="wen" class="row-line" style="border: none;">
            忘记密码
            <text style class="iconfont icon-xiangyou arrow"></text>
          </view>-->
        </view>
        <view class="big-line relative_1" v-if="false">
          <view @click="wen" class="row-line" style="border: none;">
            绑定微信账号
            <text style="float: right;color: #999999;">Steve</text>
            <text style class="iconfont icon-xiangyou arrow"></text>
          </view>
        </view>
        <view class="big-line">
          <view class="row-line flex justify-between">
            <text>首页推荐</text>
            <view class="flex items-center">
              <u-switch v-model="checkedIsRecommend" :loading="msgLoading" active-color="#1FB0AD" @change="changeRecommend"></u-switch>
            </view>
          </view>
          <view @click="outAccount" class="row-line" style="text-align: center;">注销账号</view>
          <view @click="logout" class="row-line" style="border: none;text-align: center;">退出登录</view>
        </view>
      </view>
    </view>
    <view class="tac fs22 text-999 pb30">
      <view>Copyright@2024-2024</view>
      <view>上海懂鲜帝供应链管理有限公司版权所有</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      myBgSrc: require('@/static/my/bg1.png'),
      myphoneSrc: require('@/static/my/ic_contact.png'),
      mywhatSrc: require('@/static/my/ic_link.png'),
      background: { background: 'linear-gradient(180deg, #0078FF 0%, #1fb0ac 100%)' },
      work: {},
      list: [],
      mobile: '',
      checkedIsRecommend: false,
      msgLoading: false,
    }
  },
  onShow() {
    // this.post('/api/client/info', then(res)=> {
    //   console.log('%c [ res ]-63', 'font-size:13px; background:pink; color:#bf2c9f;', res)
    // })
    this.post('api/client/info', '', false).then(res => {
      console.log(res)
      console.log('%c [ res.code ]-97', 'font-size:13px; background:pink; color:#bf2c9f;', res.code)
      this.checkedIsRecommend = res.data.is_recommend === 0 ? false : true
    })
    // RECEIVE_WAP_PUSH
  },
  onLoad() {
    this.wenti()
    this.dian()
    // this.wo()
  },
  onPullDownRefresh() {
    this.wenti()
    // this.wo()
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 1500);
  },
  methods: {
    changeRecommend() {
      if (this.msgLoading) return
      this.msgLoading = true
      let data = {
        type: 'recommend',
        val: this.checkedIsRecommend ? 1 : 0
      }
      this.post('/api/client/pushSet', data, true).then(res => {
        if (res.code == 1) {
          this.$u.toast('设置成功')
          uni.setStorageSync('is_push_msg', data.val)
        }
        this.msgLoading = false
      })
    },
    toPrivate(val) {
      uni.navigateTo({
        url: '/sub/pages/my/private/index?type=' + val
      })
    },
    async outAccount() {
      let { code } = await this.post('api/client/cancelAccount', {}, true)
      if (code == 1) {
        this.$store.commit('logout')
        this.toPageIndex('已成功注销账号')
      }
    },
    toPageIndex(msg) {
      this.$u.toast(msg)
      setTimeout(() => {
        uni.switchTab({
          url: '/pages/index/index'
        })
      }, 1000)
    },
    dian: function () {
      this.post('api/index/site', '', true).then(res => {
        console.log(res)
        if (res.code == 1) {
          this.mobile = res.data.service_mobile
        }
      })
    },
    // 增加访问量
    yang: function () {
      this.post('api/homepage/pageviews', { path: '/subpages/pages/lianxi' }, true).then(res => {
        console.log(res)
      })
    },
    back: function () {
      uni.navigateBack({
        delta: 1
      })
    },
    // 问题列表
    wenti: function () {
      this.post('api/index/problem', '', true).then(res => {
        console.log(res)
        if (res.code == 1) {
          this.list = res.data
        }
      })
    },
    // 联系我们
    wo: function () {
      this.post('api/help/contact', '', true).then(res => {
        console.log(res)
        if (res.code == 1) {
          this.work = res.data
        }
      })
    },
    logout: function (id) {
      this.post('api/user/logout', '', true).then(res => {
        console.log(res)
        if (res.code == 1) {
          this.$store.commit('logout')
          this.toPageIndex('已退出登录')
        } else {
          this.$u.toast(res.msg)
        }
      })

    }

  }
}
</script>

<style lang="scss">
page {
  background-color: #f5f5f5 !important;
  font-family: Demibold;
}
.setting_container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.gradient-bg {
  width: 100%;
  height: 366rpx;
  background: linear-gradient(180deg, #1fb0ac 0%, #f5f5f5 100%);
  position: relative;
  padding-top: 40rpx;
}
.wdbg {
  width: 100%;
  height: 566rpx;
}
.big-line {
  width: 100%;
  background-color: #ffffff;
  border-radius: 16rpx;
  box-sizing: border-box;
  margin-bottom: 50rpx;
}
.row-line {
  line-height: 120rpx;
  box-sizing: border-box;
  color: #333333;
  font-size: 28rpx;
  position: relative;
  border-bottom: 1px solid #eeeeee;
  width: 88%;
  margin: 0 auto;
}
.arrow {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  color: #cccccc;
}
.slot-wrap {
  display: flex;
  align-items: center;
  /* 如果您想让slot内容占满整个导航栏的宽度 */
  /* flex: 1; */
  /* 如果您想让slot内容与导航栏左右有空隙 */
  padding: 0 30rpx;
}
button {
  border: none;
  background-color: none;
}
button[type="default"] {
  border: none;
  background-color: none;
}
button:after {
  border: none;
  background-color: none;
}
</style>

